package wwl.lsf.hellospringboot.test;

import java.util.HashMap;
import java.util.Map;

class Solution {

  public static void main(String[] args) {

//    int[] nums = {1, 3, 5, 6};
//    int target = 9;
//    get(nums, target);
//    jisuan();
  }

  /*public static int[] twoSum(int[] nums, int target) {
    Map<Integer, Integer> map = new HashMap<>();
    for (int i = 0; i < nums.length; i++) {
      int complement = target - nums[i];
      if (map.containsKey(complement)) {
        System.out.print(i);
        System.out.print(",");
        System.out.print(map.get(complement));
        return new int[]{map.get(complement), i};
      }
      map.put(nums[i], i);
    }
    throw new IllegalArgumentException("No two sum solution");
  }*/

  public static int[] get(int nums[], int target) {

    for (int i = 0; i < nums.length; i++) {
      for (int j = i + 1; j < nums.length; j++) {
        if ((nums[i] + nums[j]) == target) {
          int[] result = new int[2];
          result[0] = i;
          System.out.println(i);
          result[0] = j;
          System.out.println(j);
          return result;
        }
      }
    }
    return null;
  }

  public static int[] jisuan(int[] nums, int target) {
//    int[] nums = {1, 3, 5, 6};
//    int target = 9;
    Map<Integer, Integer> lll = new HashMap<>();
    for (int i = 0; i < nums.length; i++) {
      int i1 = target - nums[i];
      if (lll.containsKey(i1)) {
        System.out.println(i);
        System.out.println(lll.get(i1));
        int result[] = {i, lll.get(i1)};
        return result;
      } else {
        lll.put(nums[i], i);
      }

    }
    return null;
  }
}
